package io.renren.utils.util.db.transaction;

import java.sql.Connection;

import org.apache.log4j.Logger;

import io.renren.utils.util.DatabaseUtil;
import io.renren.utils.util.exception.XMTException;

/**
 * @author Clark Liu
 * 
 */
public class DBTransactionManager implements TransactionManager {
	protected static Logger logger = Logger.getLogger(DBTransactionManager.class.getName());
	
//	private DBTransaction transaction = null;

//	public DBTransaction createTransaction(DataSource ds) throws SQLException {
//		return createTransaction(ds.getConnection());
//	}
	
	public static DBTransaction createTransaction(Connection connection) {
		return new DBTransaction(connection);
	}
	
	public static DBTransaction createTransaction() throws TransactionException {
		DBTransaction transaction = null;
		Connection connection = null;
		try {
			connection = DatabaseUtil.getConnection();
		} catch (XMTException e) {
			// TODO Auto-generated catch block
			throw new TransactionException("Cannot create connection for DB transaction", e);
		}
		transaction = createTransaction(connection);
		return transaction;
	}

//	public DBTransaction getTransaction() {
//		return transaction;
//	}
	
}
